package org.hackystat.ambientdevice.device;

import static org.junit.Assert.assertTrue;
import org.hackystat.ambientdevice.ConfigurationException;
import org.hackystat.ambientdevice.device.bunny.Nabaztag;
import org.hackystat.ambientdevice.device.orb.AmbientOrb;
import org.hackystat.ambientdevice.server.jaxb.Device;
import org.junit.Test;

/**
 * Test class for DeviceFactory.
 * 
 * @author ZsxKiNG
 * 
 */
public class TestDeviceFactory {

  /**
   * Test device factory.
   * 
   * @throws ConfigurationException when error occurs.
   */
  @Test
  public void testDeviceFactory() throws ConfigurationException {
    DeviceFactory factory = new DeviceFactory();
    Device orb = new Device();
    orb.setDeviceType("AmbientOrb");
    assertTrue("Check type", factory.getDevice(orb) instanceof AmbientOrb);
    Device bunny = new Device();
    bunny.setDeviceType("Nabaztag");
    assertTrue("Check type", factory.getDevice(bunny) instanceof Nabaztag);
    Device device = new Device();
    try {
      factory.getDevice(device);
    }
    catch (ConfigurationException e) {
      assertTrue("Check exception message.", e.getMessage().contains("is null"));
    }
    device.setDeviceType("Tester");
    try {
      factory.getDevice(device);
    }
    catch (ConfigurationException e) {
      assertTrue("Check exception message.", e.getMessage().contains("Tester"));
    }
  }
}
